package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.顾客订单记录Model;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created by ThinkPad on 2016/9/2.
 */
@Transactional
public interface 顾客订单记录Repository extends JpaRepository<顾客订单记录Model, Integer>, JpaSpecificationExecutor<顾客订单记录Model> {

    @Query("select a from 顾客订单记录Model a where a.顾客编号=?1 and a.许可=?2")
    List<顾客订单记录Model> findOrderRecordByCusIdAndPermit(int cusId, String permit);

    @Modifying
    @Query("update  顾客订单记录Model a set a.状态='交车后退车' where a.顾客编号=?1 and a.车型=?2 and a.销售顾问=?3")
    int updateStatusByCustIdAndCarId(int custId, int carId, String sc);

    @Query("select a from 顾客订单记录Model a where ((a.状态='已订单' and a.订单日期>=?1) or (a.状态='已交车' and a.交车日期>=?1)) and a.许可=?2 and a.顾客编号=?3")
    List<顾客订单记录Model> findByDates(Date dt, String permit, Integer cusId);

    @Modifying
    @Query("update  顾客订单记录Model a set a.状态=?1 where a.顾客编号=?2 and a.库存编号=?3 ")
    int unsubscribeOrder(String status,int custId, int stockId);


    @Query("select a from 顾客订单记录Model a where a.顾客编号=?1 and a.库存编号=?2")
    List<顾客订单记录Model> findOrderByCustIdAndSrockId(Integer cusId, Integer stockId);

    @Modifying
    @Query("update 顾客订单记录Model a set a.销售顾问=?1 where a.顾客编号=?2 AND  a.库存编号=?3 ")
    int updateGkddInfo(String xsgw, Integer gkbh, Integer kcbh);
}
